# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=openFPGALoader
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.13.1
pkgrel=1
pkgdesc="openFPGALoader: universal utility for programming FPGA (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/trabucayre/openFPGALoader"
license=('spdx:Apache-2.0')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=(
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
  "${MINGW_PACKAGE_PREFIX}-libftdi"
  "${MINGW_PACKAGE_PREFIX}-libusb"
  "${MINGW_PACKAGE_PREFIX}-zlib"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
)
source=("https://github.com/trabucayre/openFPGALoader/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('372f1942dec8a088bc7475f94ccf5a86264cb74e9154d8a162b8d4d26d3971e3')

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL=- cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    ../"${_realname}-${pkgver}"

  cmake --build .
}

check() {
  "${srcdir}"/build-${MSYSTEM}/openFPGALoader.exe --help
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" cmake --install .

  _licenses="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${_licenses}"
  install -m 644 "${srcdir}/${_realname}-${pkgver}"/LICENSE "${_licenses}"
}
